import React, { Component } from 'react'

export default class App extends Component {
  state = {
    firstName: '',
    lastName: ''
  }
  changeHandler = (e) => {
    console.log(e.target.name)
    this.setState({
      // 对象的key值如果为变量，可以使用[变量]表示
      [e.target.name]: e.target.value
    })
  }
  render() {
    return (
      <div>
        <input name="firstName" onChange = { this.changeHandler } value = { this.state.firstName } type="text" placeholder ="姓"/>
        + 
        <input name="lastName" onChange = { this.changeHandler } value = { this.state.lastName } type="text" placeholder="名"/>
        = { this.state.firstName + this.state.lastName }

      </div>
    )
  }
}
